#@layout()
#define script()
<script>

	function trash(id) {
		ajaxGet("#(CPATH)/admin/product/doTrash/" + id);
	}


	function draft(id) {
		ajaxGet("#(CPATH)/admin/product/doDraft/" + id);
	}

	function normal(id) {
		ajaxGet("#(CPATH)/admin/product/doNormal/" + id);
	}

	function del(id) {
		if (confirm('确定要删除该产品吗？删除后不可恢复')) {
			ajaxGet("#(CPATH)/admin/product/doDel/" + id);
		}
	}

</script>

#end

#define content()

	<section class="content-header">
		<div class="container-fluid">
			<div class="row">
				<div class="col-sm-6">

					<div class="row mb-2">
						<div class="col-sm-12">
							<h1>
								商品管理
								<small data-toggle="tooltip" title="" data-placement="right"
									   data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
								<small> 首页 / 商品 / 商品管理</small>
							</h1>
						</div>
					</div>

					<div class="row">
						<div class="col-12" style="padding-top: 20px">
							<a href="#(CPATH)/admin/product/list">全部 (#(totalCount ??))</a> |
							<a href="?status=1">已发布 (#(normalCount ??))</a> |
							<a href="?status=2">草稿 (#(draftCount ?? 0))</a> |
							<a href="?status=3" style="color: #a00">垃圾箱 (#(trashCount ?? 0))</a>
						</div>
					</div>

				</div>
				<div class="col-sm-6 ">
					<div class=" float-sm-right" style="padding-top: 45px">
						<a href="./edit" type="button" class="btn btn-primary"><i class="fas fa-plus"></i>新建</a>
					</div>
				</div>

			</div>

		</div><!-- /.container-fluid -->
	</section>

	<section class="content">
		<div class="container-fluid">
				<div class="card card-outline card-primary">
					<div class="card-header with-border">
						<form class=" admin-search-panel" action="" method="get">
							<input type="hidden" name="status" value="#para('status')">
							<div class="row">
								<div class="form-group col-lg-2">
										<input type="text" placeholder="标题" class="form-control" name="title" value="#para('title')">
								</div>
								<div class="form-group col-lg-2">
										<select class="form-control" name="categoryId">
											<option value="">全部分类</option>
											#for(category : categories)
											<option value="#(category.id ??)" #selectedIf(category.isCheck)>
												#(category.layerString) #(category.title ??)
											</option>
											#end
										</select>
								</div>
								<div class="form-group col-lg-2">
										<button type="submit" class="btn btn-primary ">查询</button>
										<button type="reset" class="btn btn-default">重置</button>
								</div>
							</div>
							<!-- /.card-body -->
						</form>

					</div>
					<!-- /.card-header -->
					<div class="card-body p-0">

						<table class="table table-striped">
							<tbody>
							<tr>
								<th style="width: 10px">
									<input class="tableCheckAll" id="checkall" type="checkbox" value="0"/>
								</th>
								<th style="width: 350px">标题</th>
								<th style="width: 50px">价格</th>
								<th style="width: 50px">销量</th>
								<th>分类</th>
								<th>标签</th>
								<th style="width: 50px"><i class="fa fa-commenting"></i></th>
								<th style="width: 90px">发布时间</th>
							</tr>

							#for(product : page.list)
							<tr>
								<td><input name="tableItem" type="checkbox" value="#(product.id)"/>
								</td>
								<td>
									<!--<div style="width: 20px;height: 20px">-->
										<!--<img src="#(CPATH)#(product.thumbnail ??)" style="width: 100%;height: 100%">-->
									<!--</div>-->
									<!--<div style="float: right">-->
										<strong>
											<a href="#(CPATH)/admin/product/edit/#(product.id)">#(product.title ??)</a>
											#if(product.isDraft())
											（草稿）
											#end
										</strong>
										<div class="jp-action-card">
											#if(product.isNormal())
											<div class="jp-action-body">
												<a href="#(CPATH)/admin/product/edit/#(product.id)">编辑</a> |
												<a href="javascript:;" onclick="draft('#(product.id??)')">草稿</a>
												|
												<a href="javascript:;" onclick="trash('#(product.id??)')"
												   class="red-action">垃圾箱</a> |
												<a href="#(product.url ??)" target="_blank" class="red-action">查看</a>
											</div>
											#elseif(product.isDraft())
											<div class="jp-action-body">
												<a href="#(CPATH)/admin/product/edit/#(product.id)">编辑</a> |
												<a href="javascript:;" onclick="trash('#(product.id??)')"
												   class="red-action">垃圾箱</a>
											</div>
											#else
											<div class="jp-action-body">
												<a href="javascript:;" onclick="draft('#(product.id??)')">还原</a>
												|
												<a href="javascript:;" onclick="del('#(product.id??)')" class="red-action">永久删除</a>
											</div>
											#end
										</div>
									<!--</div>-->

								</td>
								<td style="white-space:nowrap">
										#(product.price ??)
								</td>
								<td style="white-space:nowrap">
										#(product.real_sales_count ?? '0' )（#(product.sales_count ?? '0')）
								</td>
								
								<td>
									#productCategories(product.id,"category")
									#for(category : categories)
									<a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
									#if(!for.last) , #end
									#end
									#end
								</td>
								<td>
									#productCategories(product.id,"tag")
									#for(category : categories)
									<a href="#(category.url ??)" target="_blank">#(category.title ??)</a>
									#if(!for.last) , #end
									#end
									#end
								</td>
								<td>
									<a href="#(CPATH)/admin/product/comment?productId=#(product.id)">
										#(product.comment_count ??)
									</a>
								</td>
								<td>#date(product.created)</td>
							</tr>
							#end

							</tbody>
						</table>
					</div>
					<!-- /.card-body -->
					<div class="card-footer">
						<div class="row">
							<div class="col-sm-6">
								<div class="row">

									<div class="form-group">
										<div class="form-check">
											<input class="form-check-input tableCheckAll" id="checkall" type="checkbox" >
											<label class="form-check-label" for="checkall">全选</label>
										</div>
									</div>
									<div class="form-group col-lg-3">
										<select class="form-control" name="action">
											<option value="">请选择...</option>
											<option value="doDelByIds" open-type="del-confirm">
												批量删除
											</option>
										</select>
									</div>

									<div class="form-group col-lg-3">
										<button type="button" class="btn btn-outline-primary batchExec">批量操作</button>
									</div>
								</div>
							</div>

							<div class="col-sm-6">
								#@_paginate()
							</div>
						</div>
					</div>
					<!-- /.card-footer -->
				</div>
				<!-- /.card -->
			</div>
	</section>
#end
